package com.itheima.springmvc.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class CustomHandleException implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object,
			Exception exception) {
		//定义异常信息
		String msg;
		//判断异常类型
		if(exception instanceof MyException) {
			MyException me = (MyException)exception;
			msg = me.getMessage();
		} else {
			msg = "未知异常";
		}
		ModelAndView mav = new ModelAndView();
		mav.addObject("msg", msg);
		mav.setViewName("error");
		return mav;
	}

}
